import { CHANGE_INPUT_VALUE, ADD_TODO_ITEM, DELETE_ITEM, INIT_DATA } from './actionTypes.js';
import axios from 'axios';

export const getInputChangeAciton = (value) => ({
  type: CHANGE_INPUT_VALUE,
  value
})

export const getClickBtnAction = () => ({
  type: ADD_TODO_ITEM
})

export const getDeleteItemAction = (index) => ({
  type: DELETE_ITEM,
  index
})

export const getInitAction = (data) => ({
  type: INIT_DATA,
  data
})

export const getListAction = () => {
  return (dispatch) => {
  	axios.get('/list.json').then((res) => {
  		const data = res.data;
  		const action = getInitAction(data);
  		dispatch(action);
  	})
  }
}